package com.sskj.xgja.market;

import com.sskj.xgja.BasePresenter;
import com.sskj.base.utils.RxUtils;
import com.sskj.xgja.api.Api;
import com.sskj.xgja.api.ApiObserver;
import com.sskj.xgja.market.bean.BannerNoticeBean;
import com.sskj.xgja.market.bean.MarketData;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/03/20
 */
class MarketHomePresenter extends BasePresenter<MarketHomeFragment> {
    public void getMarketList(boolean showLoading) {
        Api.getInstance().marketList()
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<List<MarketData>>(this, showLoading) {
                    @Override
                    public void onSuccess(List<MarketData> data) {
                        mView.setMarketList(data);
                    }


                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mView.setMarketList(null);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }

    public void getBanner() {
        Api.getInstance().getBanner()
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<BannerNoticeBean>(this, true) {
                    @Override
                    public void onSuccess(BannerNoticeBean data) {
                        mView.setBanner(data.getBanner());
                        mView.setNotice(data.getArticle());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }

}
